<!-- Put IE into quirks mode -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<!-- ext lib -->
		<link type="text/css" rel="stylesheet"
			href="/extdemo/ext-3.0.0/resources/css/ext-all.css"></link>
		<script type="text/javascript"
			src="/extdemo/ext-3.0.0/adapter/ext/ext-base.js"></script>
		<script type="text/javascript" src="/extdemo/ext-3.0.0/ext-all.js"></script>
		<!-- end ext lib -->

		<title>用户注册</title>

		<style>
</style>
		<script>
	
		var userNameTextField = new Ext.form.TextField({
			fieldLabel : 'username',
			anchor : '100%'
			
		});
		
		var checkmsg = new Ext.Panel({id:"checkmsg"});
		
		var loginButton = new Ext.Button({
			text : '检测',
			handler : login
		});
		var loginForm = new Ext.form.FormPanel({
			layout : 'form',
			items:[userNameTextField, checkmsg],
			buttons:[loginButton]
		
		});
		Ext.onReady(function(){
			
			var loginWin = new Ext.Window({
				width : '400',
				height : 200,
				title: '',
				modal:true,
    			items: [loginForm]
    		});
    		
    		loginWin.show();
		});
		
		//登陆
		function login(){
			Ext.Ajax.request({
				url: '/servlet/CheckServlet',
				params : {
			   		username : userNameTextField.getValue(),
			   	    datatype : "html"
				},
				success: function(resp,opts){
					//var json = Ext.util.JSON.decode(resp.responseText);
					/* if ( resp.responseText == "1") {
						alert("登陆成功!");
						return;
					}
					alert("登陆失败 !"); */
					//$("checkmsg").innerHTML = resp.responseText;
					parseMessage(resp.responseText, "html")
				}
		    });
		}
		
		function parseMessage(xmlhttp, dataType) {
			var flag;
			var info;
			if (dataType == "xml") {
				var xmlDoc = xmlhttp;
				var result = xmlDoc.getElementsByTagName('result');
				var node = xmlDoc.getElementsByTagName('info');
				flag = (result && result[0].firstChild.nodeValue == "true") ? true : false;
				info = node[0].firstChild.nodeValue;

			} else if (dataType == "html") {
				var txtDoc = xmlhttp;
				var result = txtDoc.split("$$");
				flag = (result[0] && result[0] == "true") ? true : false;
				info = result[1];
			} else if (dataType == "json") {
				var txtDoc = xmlhttp;
				flag = txtDoc.result;
				info = txtDoc.info;
			}
			$('checkmsg').style.color = (flag ? "green" : "red");
			$("checkmsg").innerHTML = userNameTextField.getValue() + " " + info;
		}
		
		function $(id) {
			return document.getElementById(id);
		}
	</script>
	</head>

	<body>

	</body>
</html>
